package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.ProjFilesLogic;
import cn.topevery.garden.entity.dto.ProjFilesDTO;
import cn.topevery.garden.entity.query.ProjFilesQuery;
import cn.topevery.garden.entity.vo.ProjFilesVO;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 项目附件表
 *
 * @author code-generate
 * @date 2022-11-02
 */
@Api(tags = "工程项目-项目附件表")
@RestController
@RequestMapping("/projFiles")
public class ProjFilesController extends BaseController {

    @Autowired
    ProjFilesLogic projFilesLogic;

    /**
     * 获取项目附件表分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取项目附件表页列表")
    @GetMapping("/listPage")
    public JsonResult<DataPager<ProjFilesVO>> listPage(ProjFilesQuery query) {
        return JsonResult.ok(projFilesLogic.listPage(query));
    }

    /**
     * 获取项目附件表列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取项目附件表列表")
    @GetMapping("/list")
    public JsonResult<List<ProjFilesVO>> list(ProjFilesQuery query) {
        return JsonResult.ok(projFilesLogic.list(query));
    }

    /**
     * 根据自增ID批量删除
     *
     * @param dto
     * @return
     */
    @ApiOperation("根据自增ID批量删除")
    @PostMapping("/deleteBatchById")
    public JsonResult<Boolean> deleteBatchById(@RequestBody ProjFilesDTO dto) {
        projFilesLogic.delete(getUser().userId, dto.getIds());
        return JsonResult.ok(true);
    }

    @ApiOperation("新增/编辑 项目附件表信息")
    @PostMapping("/saveOrUpdate")
    public JsonResult<Boolean> saveOrUpdate(@Valid @RequestBody ProjFilesDTO dto) {
        return JsonResult.ok(true);//projFilesLogic.saveOrUpdate(CurrentUserUtil.getUser().userId,dto));
    }

    @ApiOperation("根据guid获取详情")
    @GetMapping("/getByGuid")
    public JsonResult<ProjFilesVO> getByGuid(@RequestParam(value = "guid") String guid) {
        ProjFilesVO vo = new ProjFilesVO();
//        DataFillHelper.readToTarget(projFilesLogic.getEntityByDataId(guid), vo);
        return JsonResult.ok(vo);
    }

    @ApiOperation("导出项目附件表信息")
    @GetMapping("/export")
    public void export(ProjFilesQuery query, HttpServletResponse response) {
        List<ProjFilesVO> list = projFilesLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "项目附件表", "sheet1", ProjFilesVO.class, "项目附件表", response);
    }

}
